package com.example.collegevice.mapper;


import com.example.pojo.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface CourseMapper {
    @Insert("insert into course(name, content, score, teacher_id, num, time,location, college_id,already_num) " +
            "values(#{name}, #{content},#{score}, #{teacherId}, #{num}, #{time},#{location},#{collegeId}, #{alreadyNum})")
    void insert(Course course);

//    @Select("select course.*, college.name as collegeName, teacher.name as teacherName from course " +
//            "left join college on course.college_id = college.id " +
//            "left join teacher on course.teacher_id = teacher.id")
    @Select(("select * from course"))
    List<Course> selectAll();

//    @Select("select course.*, college.name as collegeName, teacher.name as teacherName from course " +
//            "left join college on course.college_id = college.id " +
//            "left join teacher on course.teacher_id = teacher.id " +
//            "where course.name like concat('%', #{name}, '%')")
    @Select("select * from course where name like concat('%', #{name}, '%')")
    List<Course> selectByName(String name);

    @Update("update course set name = #{name},content = #{content},score = #{score}," +
            "teacher_id = #{teacherId},num = #{num},time = #{time},location = #{location}," +
            "college_id = #{collegeId},already_num = #{alreadyNum}" + " where id = #{id}")
    void updateById(Course course);

    @Delete("delete from course where id = #{id}")
    void deleteById(Integer id);

//    @Select("select course.*, college.name as collegeName, teacher.name as teacherName from course " +
//            "left join college on course.college_id = college.id " +
//            "left join teacher on course.teacher_id = teacher.id " +
//            "where course.name like concat('%', #{name}, '%') and teacher_id = #{teacherId}")
    @Select("select * from course where name like concat('%', #{name}, '%') and teacher_id = #{teacherId}")
    List<Course> selectByNameAndTeacherId(@Param("name") String name, @Param("teacherId") Integer teacherId);

//    @Select("select course.*, college.name as collegeName, teacher.name as teacherName from course " +
//            "left join college on course.college_id = college.id " +
//            "left join teacher on course.teacher_id = teacher.id " +
//            "where teacher_id = #{teacherId}")
    @Select("select * from course where teacher_id = #{teacherId}")
    List<Course> selectAllByTeacherId(Integer teacherId);

    @Select("select * from course where id = #{id}")
    Course selectById(Integer courseId);
}
